<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<link rel="stylesheet" href="css/bootstrap-3.3.7/css/bootstrap.min.css" />
<link rel="stylesheet" href="css/register.css" />
<link rel="stylesheet" href="css/listCommon.css" />
<link rel="stylesheet" href="css/evaluation.css" />
<%-- 导入面包屑 --%>
<jsp:include page="../common/nav.jsp"></jsp:include>
<style>
	.redragon-head-title{
		font-size: 20px;
		color: #2972FA;
		border-left: 4px solid #2972fa;
		padding-left: 15px;
		margin-bottom: 30px;
	}
	.ibox-content {
		border-width: 0px;
	}
	.saveBtn{
		background: #2c74fa;
		margin-left: 20px;
		border: none;
		color: #fff;
	}
	.btnBack{
		background: #ddd;
		margin-left: 20px;
		border: none;
		color: #fff;
	}
	.btn-change{
		background: #f8ac59;
		margin-left: 20px;
		border: none;
		color: #fff;
	}
	.btn-submit{
		background: #e36858;
		margin-left: 20px;
		border: none;
		color: #fff;
	}
	.form-control[disabled], .form-control[readonly], fieldset[disabled] .form-control {
		background-color: #fff;
	}
</style>
<div class="wrapper wrapper-content animated fadeInRight">

	<%-- 导入提示信息框 --%>
	<c:if test="${hint!=null&&hint!=''}">
		<jsp:include page="../common/alert/alert.jsp">
			<jsp:param value="${hint}" name="alertType"/>
			<jsp:param value="${alertMessage}" name="alertMessage"/>
		</jsp:include>
	</c:if>

	<div class="row">
		<div class="col-lg-12">
			<div class="ibox ">

					<h5><span class="redragon-head-title">换货单头信息</span></h5>
					<div class="ibox-tools">
						<i class="fa fa-chevron-up"></i>
					</div>


				<div id="ibox-content" class="ibox-content border-bottom" style="padding-bottom: 0px;">
					<form id="form" action="web/invInputHead/editInvInputHeadSwap" method="post">

						<div class="tabs-container">
							<ul class="nav nav-tabs">
								<li><a class="nav-link active" data-toggle="tab" href="#mainTab">标准信息 </a></li>
								<li><a class="nav-link" data-toggle="tab" href="#otherTab">自定义 <i class="fa fa-puzzle-piece"></i></a></li>
							</ul>
							<div id="headTabDiv" class="tab-content">

								<!-- mainTab开始 -->
								<div id="mainTab" class="tab-pane active">
									<div class="panel-body" style="padding-bottom: 0px; border-bottom: 0px;">

										<div class="row">
											<div class="col-md-6">
												<div class="form-group">
													<span>*</span>
													<label>类型：</label>
													<select class="form-control" name="inputType" id="inputType">
														<%--<option value="" selected="selected">请选择...</option>--%>
														<c:forEach items="${requestScope.inputTypeMap}" var="inputType">
															<option value="${inputType.key}">${inputType.value}</option>
														</c:forEach>
													</select>
												</div>
											</div>
											<div class="col-md-6">
												<div class="form-group">
													<span>&nbsp</span>
													<label id="HeadCodeLabel">换货单编码：</label>
													<input id="inputHeadCode" name="inputHeadCode" type="text" class="form-control" value="${requestScope.invInputHead.inputHeadCode}" readonly="readonly">
												</div>
											</div>
											<div class="col-md-6">
												<div class="form-group">
													<span>*</span>
													<label>仓库：</label>
													<select class="form-control" name="warehouseCode" id="warehouseCode">
														<option value="" selected="selected">请选择...</option>
														<c:forEach items="${requestScope.warehouseMap}" var="warehouse">
															<option value="${warehouse.key}" address="${warehouse.value.warehouseAddress}">${warehouse.value.warehouseName}</option>
														</c:forEach>
													</select>
												</div>
											</div>
											<div class="col-md-6">
												<div class="form-group">
													<span>&nbsp</span>
													<label>仓库地址：</label>
													<input id="warehouseAddress" type="text" class="form-control" value="${requestScope.invInputHead.warehouseAddress}" readonly="readonly">
												</div>
											</div>
											<div class="col-md-6">
												<div class="form-group">
													<span>*</span>
													<label>发货单编码：</label>
													<input id="inputSourceHeadCode" name="inputSourceHeadCode" type="text" class="form-control" value="${requestScope.invInputHead.inputSourceHeadCode}">
												</div>
											</div>
											<div class="col-md-6">
												<div class="form-group">
													<span>*</span>
													<label>配送方式：</label>
													<select class="form-control" name="inputSourceType" id="inputSourceType">
														<option value="" selected="selected">请选择...</option>
														<c:forEach items="${requestScope.deliveryMethodMap}" var="deliveryMethod">
															<option value="${deliveryMethod.key}">${deliveryMethod.value}</option>
														</c:forEach>
													</select>
												</div>
											</div>
											<%--<div class="col-md-6">
												<div class="form-group">
													<span>&nbsp</span>
													<label>发货单名称：</label>
													<input id="inputSourceHeadName" type="text" class="form-control" value="${requestScope.invInputHead.inputSourceHeadName}" readonly="readonly">
												</div>
											</div>--%>
											<div class="col-md-6">
												<div class="form-group">
													<span>*</span>
													<label>供应商：</label>
													<input id="vendorName" type="text" class="form-control" value="${requestScope.invInputHead.vendorName}" readonly="readonly">
												</div>
											</div>
											<div class="col-md-6">
												<div class="form-group">
													<span>&nbsp</span>
													<label>供应商联系人：</label>
													<input id="vendorContactDesc" type="text" class="form-control" value="${requestScope.invInputHead.vendorContactDesc}" readonly="readonly">
												</div>
											</div>
											<div class="col-md-6">
												<div class="form-group">
													<span>&nbsp</span>
													<label>换货原因：</label>
													<input id="memo" name="memo" type="text" class="form-control" value="${requestScope.invInputHead.memo}">
												</div>
											</div>
											<div class="col-md-6">
												<div class="form-group">
													<span>*</span>
													<label id="dateLabel">换货日期：</label>
													<input id="inputDate" name="inputDate" type="text" class="form-control" value="${requestScope.invInputHead.inputDate}" autocomplete="off">
												</div>
											</div>
											<div class="col-md-6">
												<div class="form-group">
													<span>*</span>
													<label>状态：</label>
													<input type="text" class="form-control" value="${requestScope.inputStatusMap[requestScope.invInputHead.status]}" readonly="readonly">
												</div>
											</div>
											<div class="col-md-6">
												<div class="form-group">
													<span>*</span>
													<label>制单人：</label>
													<input id="staff_code" name="staff_code" type="text" class="form-control" value="${requestScope.invInputHead.staffName}" readonly="readonly">
												</div>
											</div>
											<div class="col-md-6">
												<div class="form-group">
													<span>*</span>
													<label>制单部门：</label>
													<input id="department_code" name="department_code" type="text" class="form-control" value="${requestScope.invInputHead.departmentName}" readonly="readonly">
												</div>
											</div>


											<div class="col-md-12">
												<%--<div class="form-group">--%>
													<div class="col-sm-offset-2 text-right">
														<input type="button" class="btn selectBtn" data-style="expand-right" onclick="selectBtnData()" value="查询"/>
														<%--<button class="btn btnBack" type="button" onclick="window.location.href='web/invInputHead/getInvInputHeadList'">返回</button>&nbsp;
														<c:if test="${param.inputHeadCode==null||param.inputHeadCode==''||requestScope.invInputHead.approveStatus=='UNSUBMIT'||requestScope.invInputHead.approveStatus=='REJECT' }">
															<button class="btn saveBtn" data-style="expand-right">保存</button>
														</c:if>--%>

														<c:if test="${requestScope.workflowFlag!='Y'}">
															<c:if test="${param.inputHeadCode!=null&&param.inputHeadCode!=''}">
																<c:if test="${requestScope.invInputHead.approveStatus=='UNSUBMIT'||requestScope.invInputHead.approveStatus=='REJECT' }">
																	<button class="btn btn-submit" type="button" onclick="submitData()">提交</button>&nbsp;
																</c:if>
																<c:if test="${requestScope.invInputHead.approveStatus=='SUBMIT' }">
																	<button class="btn saveBtn " type="button" onclick="approveData()">审核通过</button>&nbsp;
																	<button class="btn btn-change " type="button" onclick="rejectData()">驳回</button>&nbsp;
																</c:if>
																<c:if test="${requestScope.invInputHead.approveStatus=='APPROVE' }">
																	<button class="btn btn-change" type="button" onclick="alterData()">变更</button>&nbsp;
																</c:if>
															</c:if>
														</c:if>

														<!-- workflow -->
														<c:if test="${requestScope.workflowFlag=='Y'}">
															<c:if test="${param.inputHeadCode!=null&&param.inputHeadCode!=''}">
																<c:if test="${requestScope.invInputHead.approveStatus=='UNSUBMIT'||requestScope.invInputHead.approveStatus=='REJECT' }">
																	<button id="workflowSubmitButton" class="btn btn-primary btn-lg" type="button" onclick="workflowSubmit('INPUT','${param.inputHeadCode}','${requestScope.invInputHead.departmentCode}')">&nbsp;&nbsp;提交审批&nbsp;&nbsp;<i class="fa fa-arrow-circle-right"></i></button>&nbsp;
																</c:if>
																<c:if test="${requestScope.workflowControlFlag=='Y'}">
																	<c:if test="${requestScope.invInputHead.approveStatus=='SUBMIT' }">
																		<button id="workflowApproveButton" class="btn btn-warning btn-lg" type="button" onclick="workflowApprove('INPUT','${param.inputHeadCode}','${requestScope.invInputHead.departmentCode}')">&nbsp;&nbsp;单据审核&nbsp;&nbsp;<i class="fa fa-check-circle"></i></button>&nbsp;
																		<button id="workflowRejectButton" class="btn btn-danger btn-lg" type="button" onclick="workflowReject('INPUT','${param.inputHeadCode}','${requestScope.invInputHead.departmentCode}')">&nbsp;&nbsp;单据驳回&nbsp;&nbsp;<i class="fa fa-times-circle"></i></button>&nbsp;
																	</c:if>
																</c:if>
																<c:if test="${requestScope.invInputHead.approveStatus=='APPROVE' }">
																	<button class="btn btn-success btn-lg" type="button" onclick="alterData()">&nbsp;&nbsp;变更&nbsp;&nbsp;<i class="fa fa-retweet"></i></button>&nbsp;
																</c:if>
															</c:if>
														</c:if>

											<%--		</div>--%>
												</div>
											</div>
										</div>

										<input type="hidden" id="status" name="status" value="${requestScope.invInputHead.status}">
										<input type="hidden" id="staffCode" name="staffCode" value="${requestScope.invInputHead.staffCode}">
										<input type="hidden" id="departmentCode" name="departmentCode" value="${requestScope.invInputHead.departmentCode}">
										<input type="hidden" id="inputHeadId" name="inputHeadId" value="${requestScope.invInputHead.inputHeadId}">
										<input type="hidden" name="createdDate" value="${requestScope.invInputHead.createdDate}">
										<input type="hidden" name="createdBy" value="${requestScope.invInputHead.createdBy}">
										<input type="hidden" id="version" value="${requestScope.invInputHead.version}">

									</div>
								</div>
								<script>
									function selectBtnData() {
                                        getLineTab("${requestScope.invInputHead.inputHeadCode}");
                                    }

								</script>
								<!-- mainTab结束 -->

								<!-- otherTab开始 -->
								<div id="otherTab" class="tab-pane"></div>

								<script>
                                    $(document).ready(function(){
                                        $.ajax({
                                            type: "post",
                                            url: "web/cuxFlexFieldHead/beforeHeadFlexField",
                                            data: {"ffHeadCode": "inv_input_head"},
                                            async: true,
                                            dataType: "html",
                                            cache: false,
                                            success: function(data){
                                                if(data!=""){
                                                    $("#otherTab").html(data);
                                                    $("#attribute1").val("${requestScope.invInputHead.attribute1}");
                                                    $("#attribute2").val("${requestScope.invInputHead.attribute2}");
                                                    $("#attribute3").val("${requestScope.invInputHead.attribute3}");
                                                    $("#attribute4").val("${requestScope.invInputHead.attribute4}");
                                                    $("#attribute5").val("${requestScope.invInputHead.attribute5}");
                                                    $("#attribute6").val("${requestScope.invInputHead.attribute6}");
                                                    $("#attribute7").val("${requestScope.invInputHead.attribute7}");
                                                    $("#attribute8").val("${requestScope.invInputHead.attribute8}");
                                                    $("#attribute9").val("${requestScope.invInputHead.attribute9}");
                                                    $("#attribute10").val("${requestScope.invInputHead.attribute10}");
                                                }
                                            },
                                            error: function(XMLHttpRequest, textStatus, errorThrown){
                                                redragonJS.alert("加载自定义辅助字段错误");
                                            }
                                        });
                                    });
								</script>
								<!-- otherTab结束 -->

							</div>
						</div>



				<!-- tab 开始 -->
				<div class="row">
					<div class="col-lg-12">
						<div class="ibox ">
							<div>
								<h5 class="redragon-head-title">换货单行信息</h5>
								<div class="ibox-tools">
								</div>
							</div>
							<div class="form-group">
							<div id="ibox-content1" class="ibox-content border-bottom" style="padding-bottom: 0px;">
								<div class="tabs-container">
									<ul class="nav nav-tabs">
										<li><a class="nav-link active" data-toggle="tab" href="#lineTab" onclick="getLineTab('${requestScope.invInputHead.inputHeadCode}')">行列表</a></li>
									</ul>


										<div id="lineTab" class="tab-pane">
											<div class="panel-body" style="padding-bottom: 0px; border-bottom: 0px;">

												<div class="table-responsive">
													<table id = "eee" class="table table-stripped table-hover table-bordered border-top">
														<thead id="InvInput">

														</thead>

													</table>

												</div>

											</div>
										</div>

										<div id="selectPOLineModal"></div>
										<div id="addLineModal"></div>

                                    <div class="form-group">
                                        <input id="JSONText" name="JSONText" class="form-control" type="hidden" value=""/>
                                    </div>

								</div>
							</div>
							</div>
						</div>
					</div>
				</div>
				<!-- tab 结束 -->
				<div class="col-sm-offset-2 text-right">
				<button class="btn btnBack" type="button" onclick="window.location.href='web/invInputHead/getInvInputHeadList'">返回</button>&nbsp;
				<c:if test="${param.inputHeadCode==null||param.inputHeadCode==''||requestScope.invInputHead.approveStatus=='UNSUBMIT'||requestScope.invInputHead.approveStatus=='REJECT' }">
					<button class="btn saveBtn" data-style="expand-right">保存</button>
				</c:if>
				</div>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>

<!-- pay模式对话框 -->
<div id="headModal"></div>
<!-- 会计分录 -->
<div id="voucherEntryModal"></div>

<!-- workflow -->
<script src="js/workflow.js"></script>
<div id="approveWorkflowModal"></div>

<!-- select2 -->
<script src="js/plugins/select2/select2.full.min.js"></script>

<!-- editPage -->
<script src="js/editPage.js"></script>

<script src="js/plugins/chosen/chosen.jquery.js"></script>

<script src="css/bootstrap-3.3.7/js/address.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery-ui.js"></script>
<script src="js/bootstrap.js/bootstrap.min.js"></script>

<script src="module/webuploader/mywebuploader.js"></script>
<script src="module/webuploader/webuploader.js"></script>

<link href="css/plugins/chosen/bootstrap-chosen.css" rel="stylesheet">
<link href="module/webuploader/webuploader.css" rel="stylesheet">

<script>
    $(document).ready(function() {
        //初始化inputType
        if("${requestScope.invInputHead.inputType}"!=""){
            $("#inputType").val("${requestScope.invInputHead.inputType}");
        }
        //初始化inputSourceType
        if("${requestScope.invInputHead.inputSourceType}"!=""){
            $("#inputSourceType").val("${requestScope.invInputHead.inputSourceType}");
        }
        //初始化warehouseCode
        if("${requestScope.invInputHead.warehouseCode}"!=""){
            $("#warehouseCode").val("${requestScope.invInputHead.warehouseCode}");
        }
        //初始化inputHeadCode只读
        if("${requestScope.invInputHead.inputHeadCode}"!=""){
            $("#inputHeadCode").prop("readonly", true);
        }
        //初始化select2
        $('.select2').select2({width: "100%"});

        //设置日期插件
        $('#inputDate').datepicker({
            todayBtn : "linked",
            keyboardNavigation : true,
            forceParse : true,
            calendarWeeks : false,
            autoclose : true,
            format: 'yyyy-mm-dd',
            language: 'zh-CN',
        });

        //仓库选择效果
        $("#warehouseCode").change(function(){
            $("#warehouseAddress").val($("#warehouseCode").find("option:selected").attr("address"));
        });

        //表单
        var l = $('.ladda-button-demo').ladda();

        l.click(function() {
            $("#form").valid();
            //l.ladda('stop');
        });

        $("#form").validate({
            rules : {

                inputType : {
                    required : true,
                },
                warehouseCode : {
                    required : true,
                },

                inputSourceType : {
                    required : true,
                },
                /*inputSourceHeadCode : {
                    required : true,
                },
                */
                inputDate : {
                    required : true,
                },
            },
            submitHandler: function(form) {
                var submitFlag = "Y";

                //入库类型选择杂项入库效果
                if($("#inputType").val()=="OTHER_IN"){
                }else{
                    if($("#inputSourceType").val()==""){
                        redragonJS.alert("送货方式必填");
                        submitFlag = "N";
                        return false;
                    }

                    if($("#inputSourceHeadCode").val()==""){
                        redragonJS.alert("来源头编码必填");
                        submitFlag = "N";
                        return false;
                    }
                }

                //提交
                if(submitFlag=="Y"){

                    var tr;
                    var dataArray = new Array();

                    for(var j = 1;j < document.getElementById("eee").rows.length;j++){
                        var invNum = $("#invNum"+j).val();





                        date = new Object();
                        tr = document.getElementById("eee").rows[j];
                        date.id = tr.childNodes[0].innerHTML;
                        date.material_code = tr.childNodes[1].innerHTML;
                        date.price = tr.childNodes[4].innerHTML;
                        date.standard_unit = tr.childNodes[5].innerHTML;
                        date.allPrice = tr.childNodes[6].innerHTML;
                        date.input_quantity = invNum;

                        dataArray.push(JSON.stringify(date));

                    }

                    //document.getElementById('JSONText').value = dataArray.toString();
                    // $("#JSONText").append(dataArray.toString());
                    $('#JSONText').val(dataArray.toString());

                    l.ladda('start');
                    form.submit();
                }
            }
        });

        //初始化tab


        //变更时不允许修改来源
        if($("#status").val()=="ALTER"){
            $("#inputSourceHeadCode").prop("readonly", true);
            redragonJS.setSelectReadonly("inputSourceType", "变更时送货方式修改");
        }
    });

    //获取行tab
    function getLineTab(code){
        $.ajax({
            type: "post",
            url: "web/invInputLine/getInvInputLineList",
            data: {"supply_material_id":$("#inputSourceHeadCode").val(),"inputHeadCode": code, "version": "${param.version}", "deliveryCode": $("#deliveryCode").val()},
            async: false,
            dataType: "json",
            cache: false,
            success: function(data){
                var html="";
                $("#InvInput").html("");
                html+="<tr>"
                html+="<th width='5%'>行号</th>"

                html+="<th>物料编码</th>"
                html+="<th>物料名称</th>"
                html+="<th>规格型号</th>"
                html+="<th>单价</th>"
                html+="<th>单位</th>"
                html+="<th>小计</th>"
                html+="<th>采购数量</th>"
                html+="<th>供货数量</th>"
                html+="<th class='redragon-td-inputQuantity-title'>换货数量</th>"
                html+="</tr>"
              if(data.code == 0){
					for(var i = 0; i < data.invInputLineList.length;i++){

                        html+="<tr>"
                        html+="<td>"+(i+1)+"</td>"
                        html+="<td>"+data.invInputLineList[i]["a_material_code"]+"</td>"
                        html+="<td>"+data.invInputLineList[i]["material_name"]+"</td>"
                        html+="<td>"+data.invInputLineList[i]["standard"]+"</td>"
                        html+="<td>"+data.invInputLineList[i]["price"]+"</td>"
                        html+="<td>"+data.invInputLineList[i]["standard_unit"]+"</td>"
                        html+="<td>"+data.invInputLineList[i]["allPrice"]+"</td>"
                        html+="<td>"+0+"</td>"
                        html+="<td>"+data.invInputLineList[i]["num"]+"</td>"
                        html+="<td><input id="+'invNum'+(i+1)+" type='text' style='width: 50%' value='"+data.invInputLineList[i]["num"]+"'></td>"
                        html+="</tr>"

					}

                  $("#InvInput").append(html);

			  }


            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
                redragonJS.alert(textStatus);
            }
        });
    }
    //选择采购订单
    $("#inputSourceHeadCode").focus(function(){
        if(!$("#inputSourceHeadCode").prop("readonly")){
            getSelectPOModal();
        }
    });


    //返回采购订单选择框
    function getSelectPOModal(page){
        $('#selectPODiv').modal('hide');
        redragonJS.loading("ibox-content");
        $.ajax({
            type: "post",
            url: "web/invInputHead/getSelectDeliveryNoteModal",
            data: {"deliveryCode": $("#deliveryCode").val(), "deliveryName": $("#deliveryName").val(), "page": page,
                "supplier": $("#supplier").val()},
            async: false,
            dataType: "html",
            cache: false,
            success: function(data){
                redragonJS.removeLoading("ibox-content");
                if(data!=""){
                    $("#headModal").html(data);
                    $('#selectPODiv').modal('show');
                    $(".modal-backdrop").remove();
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
                redragonJS.alert(textStatus);
            }
        });
    }

    //重新创建凭证分录
    function autoCreateVoucherEntry(headCode){
        $.ajax({
            type: "post",
            url: "web/invInputHead/autoCreateVoucherEntry",
            data: {"headCode": headCode, "inputType": $("#inputType").val()},
            async: false,
            dataType: "json",
            cache: false,
            success: function(data){
                if(data.errCode==0){
                    redragonJS.alert("重新生成分录成功");
                }else{
                    redragonJS.alert(data.errMsg);
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
                redragonJS.alert(textStatus);
            }
        });
    }

    //提交审批
    function submitData(){
        var submitFlag = "Y";

        if($("#lineTab tbody tr").length==0){
            submitFlag = "N";
            redragonJS.alert("至少新增一行后，才能提交数据");
        }

        //提交
        if(submitFlag=="Y"){
            window.location.href='web/invInputHead/updateApproveStatus?code=${requestScope.invInputHead.inputHeadCode}&approveStatus=SUBMIT';
        }
    }

    //审批通过
    function approveData(confirmFlag){
        if(confirmFlag=="N"){
            window.location.href='web/invInputHead/updateApproveStatus?code=${requestScope.invInputHead.inputHeadCode}&approveStatus=APPROVE';
        }else{
            redragonJS.confirm("确认审批通过？", function(){
                window.location.href='web/invInputHead/updateApproveStatus?code=${requestScope.invInputHead.inputHeadCode}&approveStatus=APPROVE';
            });
        }
    }

    //审批驳回
    function rejectData(){
        //redragonJS.confirm("确认审批驳回？", function(){
        window.location.href='web/invInputHead/updateApproveStatus?code=${requestScope.invInputHead.inputHeadCode}&approveStatus=REJECT';
        //});
    }

    //数据变更
    function alterData(){
        redragonJS.confirm("确认变更数据？数据变更后将产生变更历史信息！", function(){
            window.location.href='web/invInputHead/updateApproveStatus?code=${requestScope.invInputHead.inputHeadCode}&approveStatus=UNSUBMIT';
        });
    }

    //来源类型切换
    $("#inputType").change(function(){
        initInputType();
    });
    initInputType();
    function initInputType(){
        var type = "${requestScope.invInputHead.inputType}";
        if(type == ""){
            type = $("#inputType").val();
		}
        $("#dateLabel").text("换货日期");
        $("#HeadCodeLabel").text("换货单编码");

    }
    function btnOnClick(obj) {

        $.ajax({
            type: "post",
            url: "web/invInputHead/changeInput",
            async: false,
            dataType: "html",
            cache: false,
            success: function(data){
                redragonJS.removeLoading("ibox-content");
                if(data!=""){
                    $("#headModal").html(data);
                    $('#selectPODiv').modal('show');
                    $(".modal-backdrop").remove();
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
                redragonJS.alert(textStatus);
            }
        });
    }

    //为外面的盒子绑定一个点击事件
    $("#uploadImgBtn0").click(function(e){

        imagesUpload(e);
    })

    function imagesUpload(e){

        var cid=e.currentTarget.id;
        var s=cid.substr(cid.length-1,1);

        /*
        1、先获取input标签
        2、给input标签绑定change事件
        3、把图片回显
         */
        //1、先回去input标签
        var $input = $("#file"+s+"");
        //2、给input标签绑定change事件
        $input.on("change" , function(){
            //补充说明：因为我们给input标签设置multiple属性，因此一次可以上传多个文件
            //获取选择图片的个数
            var files = this.files;

            // 通过FormData将文件转成二进制数据
            // 文件元素
            var file = document.querySelector('[type=file]');
            // 通过FormData将文件转成二进制数据
            var formData = new FormData();
            for(var i = 0;i<files.length;i++){
                formData.append("imgs", files[i]);
            }
            var ss=formData.get("fileImage[]");

            $.ajax({
                type: "post",
                url:  "<%=basePath%>web/hrStaff/file",
                data: formData,
                dataType: "json",
                processData: false, // 告诉jQuery不要去处理发送的数据
                contentType: false, // 告诉jQuery不要去设置Content-Type请求头
                xhrFields:{withCredentials:true},
                async: true,    //默认是true：异步，false：同步。
                success: function (data) {

                    if(data!=""){
                        var url="";
                        var html = "";
                        for (var i=0;i<data.length;i++){
                            url+=data[i]+",";
                            html+="<a target='_blank' href='"+data[i]+"'>"+data[i].substr(data[i].lastIndexOf("/") + 1)+"</a>\n"
                        }
                        $("#file").val(url);
                        $("#showFile").html(html);
                    }

                },
                error: function(XMLHttpRequest, textStatus, errorThrown){
                    redragonJS.alert(textStatus);
                },
            });
        })
    }

</script>